import {VueObj} from '../main';
let wsUrl = "ws://cs.api.org:9527";
export let webstock = new WebSocket(wsUrl);
webstock.onopen = function () {
    VueObj.$eventHub.$emit("openSuccess")
};

webstock.onmessage = function (message) {
    VueObj.$eventHub.$emit("receive", message)
};

webstock.onclose = function (event) {
    console.log("websocket 断开连接");
    VueObj.$eventHub.$emit("broken", event);
    webstock = new WebSocket(wsUrl)
};

webstock.onerror = function (event) {
    webstock.close(event);
    console.log("websocket error");
};
